package com.ea.service.impl;

import com.ea.common.util.tree.MyTreeUtils;
import com.ea.common.util.tree.TreeNode;
import com.ea.domain.entity.AreaInfo;
import com.ea.mapper.AreaInfoMapper;
import com.ea.mapper.OrderFormInfoMapper;
import com.ea.mapper.SysBaseFlagMapper;
import com.ea.service.ICommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author NAME-L
 * @Description TODO
 * @className CommonServiceImpl
 * @date 2023-01-31 22:54:25
 */
@Service
public class CommonServiceImpl implements ICommonService {

    @Autowired
    private AreaInfoMapper areaInfoMapper;

    @Autowired
    private SysBaseFlagMapper baseFlagMapper;

    @Autowired
    private OrderFormInfoMapper orderFormInfoMapper;



    @Override
    public List<TreeNode<AreaInfo>> queryAllProvince() {
        List<AreaInfo> list = areaInfoMapper.queryProvince();
        return MyTreeUtils.listToTree(list , (node) ->{
            TreeNode<AreaInfo> treeNode = new TreeNode<>();
            treeNode.setId(node.getAreaId());
            treeNode.setParentId(node.getParentId());
            treeNode.setRaw(node.getAreaName());
            return treeNode;
        } , -1);
    }

    @Override
    public Map<String, String> getHomeData() {
        Map<String, String> dataMap = new HashMap<>();
        String orderBeConfirm = getOrderBeConfirm();
        String todaySalesCount = getTodaySalesCount();
        String todaySalesMoney = getTodaySalesMoney();
        String orderBeSend = getOrderBeSend();
        dataMap.put("orderBeConfirm", orderBeConfirm);
        dataMap.put("todaySalesCount", todaySalesCount);
        dataMap.put("todaySalesMoney", todaySalesMoney);
        dataMap.put("orderBeSend", orderBeSend);
        return dataMap;
    }


    public String getTodaySalesCount(){
        Integer integer = orderFormInfoMapper.selectTodayOrderCount();
        return integer.toString();

    }

    public String getTodaySalesMoney() {
        BigDecimal totalMoney = orderFormInfoMapper.selectTodayOrderTotalMoney();
        return totalMoney.toString();
    }

    public String getOrderBeSend() {
        Integer orderBeSend = orderFormInfoMapper.seleteOrderBeSend();
        return orderBeSend.toString();
    }

    public String getOrderBeConfirm() {
        Integer orderBeConfirm = orderFormInfoMapper.seleteOrderBeConfirm();
        return orderBeConfirm.toString();
    }


}
